<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<#include "../base/_meta.html"> 
<@head>
<script src="/asserts/js/ddesign-main.js" type="text/javascript"></script>
<style type="text/css">
   body{ padding:10px; margin:0;}
   #layout1{  width:100%; margin:40px;  height:400px;
              margin:0; padding:0;} 
   #menu1,.l-menu-shadow{top:30px; left:50px;}
   #menu1{  width:200px;}
</style>
<script type="text/javascript">

$(function (){
	// Layout
	$("#layout1").ligerLayout({
		space:0,
		leftWidth:'15%',
		centerWidth:'70%',
		rightWidth:'14.5%',
		bottomHeight:100,
		topHeight:60
	});
	// Menu
	$("#topmenu").ligerMenuBar({ items: [
        { text: '数据库', menu: menu1 },
        { text: '界面', menu: menu2 },
        { text: '设置', menu: menu3 },
        { text: '系统', menu: menu4 }]
    });
	var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
        [
        { text: '增加', click: treerightClickAdd, icon: 'add' },
        { text: '修改', click: treerightClickEdit, icon: 'edit' },
        { text: '删除', click: treerightClickDel, icon: 'delete' }
        ]
        })
	// Toolbar
	$("#toptoolbar").ligerToolBar({ items: [
        {text: '增加', click: itemclick, icon:'add'},
        { line:true },
        { text: '修改', click: itemclick, icon:'edit'},
        { line:true },
        { text: '删除', click: itemclick, icon:'delete' }
    ]
    });
	
	// Tree
	$("#tree").ligerTree({ 
		url: '/ddesign/main/menuTree', 
		ajaxType: 'get',
		checkbox:false,
		attribute: ['nodename', 'url'],
        onSelect: function (node){
            if (!node.data.url) return;
            var tabid = $(node.target).attr("tabid");
            if (!tabid){
                tabid = new Date().getTime();
                $(node.target).attr("tabid", tabid)
            } 
            f_addTab(tabid, node.data.text, node.data.url);
        },
		onContextmenu: function (node, e){ 
            actionNodeID = node.data.text;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
        }

	});
	// Tabs
	var height = $(".l-layout-center").height();
    $("#framecenter").ligerTab({
        height: height,
        showSwitchInTab : true,
        showSwitch: true,
        onAfterAddTabItem: function(tabdata){
            tabItems.push(tabdata);
            saveTabStatus();
        },
        onAfterRemoveTabItem: function(tabid){ 
            for (var i = 0; i < tabItems.length; i++){
                var o = tabItems[i];
                if (o.tabid == tabid){
                    tabItems.splice(i, 1);
                    saveTabStatus();
                    break;
                }
            }
        },
        onReload: function(tabdata){
            var tabid = tabdata.tabid;
            addFrameSkinLink(tabid);
        }
    });
    var tab = liger.get("framecenter");
    var tree = liger.get("tree");
    // Height changed
    function f_heightChanged(options){  
        if(tab){
            tab.addHeight(options.diff);
        }
        if(accordion && options.middleHeight - 24 > 0){
            accordion.setHeight(options.middleHeight - 24);
        }
    }
    function treerightClickAdd(){
    	var nodes = tree.getSelected();
    	if(!nodes && typeof(nodes)!="undefined" && nodes!=0){
    		$.ligerDialog.warn('请选择项目或图表进行增加。');
    		return;
    	}
    	var type = nodes.data.type;
    	if(type == 'P'){
    		var url="/ddesign/diagram/g2add?projectid="+nodes.data.id;
    		$.ligerDialog.open({ url: url, height: 305,width: 550,
    			title:'添加图表-Diagram'});
    	}else if(type='D'){
    		var url="/ddesign/table/g2add?diagramid="+nodes.data.id;
    		$.ligerDialog.open({ url: url, height: 530,width: 550,
    			title:'添加数据表-Table'});
    	}
    }
    function treerightClickEdit(){
    	var nodes = tree.getSelected();
    	if(!nodes && typeof(nodes)!="undefined" && nodes!=0){
    		$.ligerDialog.warn('请选择项目或图表进行增加。');
    		return;
    	}
    	var type = nodes.data.type;
    	if(type == 'P'){
    		var url="/ddesign/project/g2edit?projectcode="+ nodes.data.id;
    		$.ligerDialog.open({ url: url, height: 320,width: 500,
    			title:'修改项目-Project'});
    	}else if(type='D'){
    		var url="/ddesign/diagram/g2edit?diagramid="+ nodes.data.id;
    		$.ligerDialog.open({ url: url, height: 305,width: 550,
    			title:'修改图表-Table'});
    	}else if(type='T'){
    		var url="/ddesign/table/g2edit?tableid="+nodes.data.id;
    		$.ligerDialog.open({ url: url, height: 150,width: 470,
    			title:'修改数据表-Table'});
    	}
    }
    function treerightClickDel(){
    	var nodes = tree.getSelected();
    	if(!nodes && typeof(nodes)!="undefined" && nodes!=0){
    		$.ligerDialog.warn('请选择项目或图表进行增加。');
    		return;
    	}
    	var type = nodes.data.type;
    	var url="";
    	if(type == 'P'){
    		url="/ddesign/project/delete?keys="+nodes.data.id;
    	}else if(type='D'){
    		url="/ddesign/diagram/delete?keys="+nodes.data.id;
    	}else if(type='T'){
    		url="/ddesign/table/delete?keys="+nodes.data.id;
    	}    	
    	$.ligerDialog.confirm('您确定要删除选择的数据吗？', 
   			function (yes) { 
   				if(yes){
   					$.ajax({
   						url:url,
   						success:function(msg){
   				        	if(msg >= 1){
   				        		$.ligerDialog.success('成功删除 '+ msg + ' 条数据。');
   				        		relaodTree();
   				        	}else{
   				        		$.ligerDialog.error('删除数据失败。') 
   				        	}
   				    	}
   					});	
   				}
    		});
    }
    // Tab Click
    function f_addTab(tabid, text, url){
        tab.addTabItem({
            tabid: tabid,
            text: text,
            url: url,
            callback: function (){
                addShowCodeBtn(tabid); 
                addFrameSkinLink(tabid); 
            }
        });
    }
});
function relaodTree(){
	liger.get("tree").reload();
}
</script>
</@head>
<body style="padding:10px">
	<div id="layout1">
		<div position="top">
			<div id="topmenu"></div><!-- Menu -->
			<div id="toptoolbar"></div> <!-- Toolbar -->
		</div>
		<div  position="left" title="列表">
		  	<ul id="tree"></ul>
		</div>
		<div position="center" title="主窗口区" id="framecenter">
		 	<div tabid="home" title="主页" >
				
			</div> 
		</div>
		<div position="right" title="属性"></div>
		<div position="bottom" title="状态">
			欢迎进入DuDesigner设计系统V1.0，目前该系统仅支持Mysql数据库，祝您使用愉快。</br>
			作者:普雷戈多1984</br>
			EMAIL:playgod1984@163.com</br>
			QQ:471208275</br>
		</div>
	</div> 
  <div style="display:none;"></div>
</body>
</html>